<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>

<center>
<h1>CEOI 98 Day 2 Problem 3</h1>
<h1>Ball</H1>
</center>

Professor Balltazar is a big football fan. His birthday was just a couple
of days before he was going to leave for the World Cup Football '98 in
France, so his friends gave him as a present a dodecahedron-shaped puzzle
as an entertainment while watching the boring games.

<P>The puzzle has 12 equal pentagon sides, labelled with numbers 1 ...
12. The figure below shows the two hemispheres of the dodecahedron, together
with the side labelling we will use in this problem. Hemispheres are "glued"
together in such a way that the side 7 is adjacent to the sides 8, 12,
11, 2 and 6 (sides are adjacent if they share an edge). In particular,
edges <I>a</I> and <I>b</I> on the left hemisphere will be glued to the
edges <I>a</I> and <I>b</I> on the right hemisphere shown below.

<center><img src="image/218a.gif"><img src="image/218b.gif"></center>

<P>In addition to that, there are 12 pentagon-shaped tiles, also labelled
from 1 to 12. Every edge on each of the tiles is marked with a number from
the set {0, 1, 2}. Each tile can be placed on each of the twelve sides
in any of the 5 positions obtained by rotating the tile around its centre.

<P>To solve the puzzle, we need to put each tile on some of the twelve
dodecahedron sides in some position, so that every two adjacent tiles have
their common edge marked with the same number.

<P>Help Professor Balltazar to solve the puzzle !

<H2>Input</H2>
The input file <B>BALL.IN</B> contains 12 lines. For each i, 1&lt;=i&lt;=12, 
the i<SUP>th</SUP> line describes the i<SUP>th</SUP> tile
by specifying 5 numbers from the set {0, 1, 2} separated by single blank
characters. This sequence shows the edge marking of the i<SUP>th</SUP>
tile starting from an arbitrary edge (called the <B>i<SUP>th</SUP> reference
edge</B>) going in the clockwise direction.

<H2>Output</H2>
Output file <B>BALL.OUT</B> should contain the description of a solved
puzzle in 12 lines with 2 integers in each line. For each i, 1&lt;=i&lt;=12, 
the i<SUP>th</SUP> line should contain integers t[i] and
n[i] separated by a single blank character describing the tile and its
position on the i<SUP>th</SUP> side :

<P>The i<SUP>th</SUP> side will hold the tile labelled t[i].

<P>The tile can be placed on the i<SUP>th</SUP> side in five different
positions. The exact position is specified by n[i], which denotes the label
of the adjacent side which is in the direction of the t[i]<SUP>th</SUP>
reference edge (looking from the centre of the i<SUP>th</SUP> side). Precisely,
the t[i]<SUP>th</SUP> reference edge is placed on the dodecahedron edge
shared by the sides labelled i and n[i].

<P>If the puzzle can not be solved, only number -1 should be written to
the output file.

<H2>Sample Input 1</H2>
<PRE>
0 0 1 1 2
0 2 1 0 1
2 0 1 0 1
0 0 1 2 1
0 2 1 1 2
2 0 1 2 1
0 2 1 2 1
2 2 1 0 1
1 2 2 0 0
0 2 1 0 2
0 2 1 2 0
2 0 1 2 0
</PRE>

<h2>Sample Output 1</h2>
<pre>
1 2
3 7
12 4
7 9
9 1
11 8
8 2
4 6
5 4
2 12
6 3
10 7
</PRE>

<h2>Sample Input 2</h2>
<PRE>
1 0 2 0 2
2 2 2 1 2
1 1 0 0 0
1 1 0 2 1
2 1 1 1 1
1 2 2 1 1
2 1 2 2 1
2 2 0 1 0
0 1 2 1 2
2 2 1 0 0
1 2 0 2 0
2 2 2 0 1
</PRE>

<h2>Sample Output 2</h2>
<PRE>
1 2
2 7
8 2
7 1
11 4
12 2
5 2
3 12
10 5
9 3
6 10
4 7
</PRE>
</BODY>
</HTML>

